package com.reluxer.filter;

import com.reluxer.util.IpThreadLocal;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Activate(group = {CommonConstants.CONSUMER})
public class TransportIPFilter implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
//        String host = RpcContext.getContext().getLocalHost();
        String host = IpThreadLocal.getIp();
        try {
            InetAddress host1 = InetAddress.getLocalHost();
            System.out.println(host1);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        RpcContext.getContext().setAttachment("consumerAddress", host);
        return invoker.invoke(invocation);
    }
}
